<template>
  <div class="left-main">
    <h3>组件库</h3>
    <div class="pack-type">
      <p>基础组件</p>
      <div class="items" @dblclick="getSub($event)">
        <div class="item" v-for="item in data" :key="item.type" :data-type="item.type">
          {{ item.name }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Left',
  data() {
    return {
      data: [
        { type: 'text', name: '文字', icon: '' },
        { type: 'img', name: '图片', icon: '' }
      ]
    }
  },
  methods: {
    getSub(event) {
      console.log(event, event.target.getAttribute('data-type'))
      let data = {
        type: event.target.getAttribute('data-type')
      }
      this.$emit('getSub', data)
    }
  }
}
</script>

<style lang="scss" scoped>
.left-main {
  width: 100%;
  height: 100%;
  padding: 10px;

  h3 {
    text-align: center;
  }

  .pack-type {

    .title {
      font-size: 16px;
    }

    .items {
      margin: 10px;
      display: flex;
      flex-wrap: wrap;

      .item {
        border: 1px solid #f1eded;
        width: 100px;
        height: 100px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 0 10px 10px 0;
        cursor: pointer;

        &:hover {
          color: #42b983;
          border-color: #42b983;
        }
      }
    }
  }
}
</style>
